package com.neu.edu.boonpay.controller;

import com.neu.edu.boonpay.pojo.Transactions;
import com.neu.edu.boonpay.pojo.dto.request.CallBackResponsePo;
import com.neu.edu.boonpay.service.BalanceService;
import com.neu.edu.boonpay.service.TransactionsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/api/v1")
public class ApiController {


    @Autowired
    private BalanceService balanceService;

    @Autowired
    private TransactionsService transactionsService;

    /**
     * Balance API
     * @param userid
     * @param token
     * @return
     */
    @PostMapping("/balance")
    public String getBalance(@RequestParam Integer userid, @RequestParam String token, HttpServletRequest request) {
        log.info("Received balance request：userid={}, token={}", userid, token);
        return balanceService.getBalance(userid, token);
    }





    /**
     * Transaction API
     * @param transactions
     * @return
     */
    @PostMapping("/transactions")
    public String sendTransactions(@RequestParam Transactions transactions) {
        log.info("Get balance request: transactions={}", transactions);
        return transactionsService.sendTransactions(transactions);
    }

    /**
     * Transaction Status API
     * @param userid
     * @param token
     * @param transid
     * @return
     */
    @PostMapping("/getTransactionStatus")
    public String getTransactionStatus(@RequestParam Integer userid,@RequestParam String token,@RequestParam String transid) {
        log.info("Transaction Status API: userid={}, token={}, transid{}", userid, token, transid);
        return transactionsService.getTransactionStatus(userid, token, transid);
    }


    @PostMapping("/callBackResponse")
    public String callBackResponse(@RequestParam CallBackResponsePo callBackResponsePo) {
        log.info("CallBack Response request：callBackResponsePo={}", callBackResponsePo);
        return transactionsService.callBackResponse(callBackResponsePo);
    }
}
